package com.funds.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.funds.dao.support.DataSourceDaoSupport;
import com.funds.domain.GoodsType;

@Repository
public class GoodsTypeDao extends DataSourceDaoSupport {

	public void insertGoodsType(GoodsType goodsType) {
		Object[] args = new Object[]{goodsType.getName(), goodsType.getDsc()};
		getJdbcTemplate().update("insert into goodstype(name, dsc) values(?, ?)", args);
	}
	

	public List<GoodsType> findAll() {
		return getJdbcTemplate().query("select * from goodstype", new GoodsTypeMapper());
	}
	
	// 类映射
	static class GoodsTypeMapper implements RowMapper {

		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			GoodsType gt = new GoodsType();
			gt.setId(rs.getInt("id"));
			gt.setName(rs.getString("name"));
			gt.setDsc(rs.getString("dsc"));
			return gt;
		}
		
	}
}
